<?php
/** 
 * 	PHP CLOUND LIBRARY
 *	Lớp đọc và xử lý dữ liệu từ file xml
 *****************************************************
 */
require_once 'Zend/Config/Xml.php';
class Clound_Xml_XmlClound extends Zend_Config_Xml
{
	protected $_arrInput;
	protected $_xml_data_col_name = 'XmlData';
	protected $_xml_data;
	protected $_xml;
	protected $_section;
	protected $_options;
	protected $_formfield_struct;
	protected $_formfield_object;
	protected $_filter_struct;
	protected $_filter_object;
	protected $_list_object;
	protected $_updateform_option;
	protected $_listform_option;
	/*
	*	Load file xml hoac chuoi xml
	*
	*
	*
	*/
    protected function _load_xml($xml = null, $section = null, $options = false)
    {
		if ($xml === null){
			if($this->_xml === null){
				return false;
			}
		}else{
			$this->_xml = $xml;
			$this->_section = $section;
			$this->_options = $options;
		}
		parent::__construct($this->_xml,$this->_section,$this->_options);
		return true;
	}
	/**
	*
	*
	**/
    protected function _load_input($arr_input=null,$xml_data_col_name=null)	
    {
		if(isset($arr_input)){
			$this->_arrInput = $arr_input;
		}
		if(isset($xml_data_col_name)){
			$this->_xml_data_col_name = $xml_data_col_name;
		}
		if(!isset($this->_arrInput)){
			return false;
		}else{
			if(!isset($this->_xml_data_col_name)){
				$this->_xml_data === null;
			}else{
				if(isset($this->_arrInput[$this->_xml_data_col_name])&&($this->_arrInput[$this->_xml_data_col_name]!='')){
					if (!class_exists('Clound_String')) {
						require_once 'Zend/Loader.php';
						Zend_Loader::loadClass('Clound_String');
					}
					$xml = '<?xml version="1.0" encoding="UTF-8"?><root>'.$this->_arrInput[$this->_xml_data_col_name].'</root>';
					//echo  htmlspecialchars($xml);exit;
					parent::__construct($xml);
					$this->_xml_data = $this->data_list->toArray();
					$this->_load_xml();
				}
			}
		}
		return true;
	}
	/*
	*	Load chuỗi xml mô tả cấu trúc formfield
	*
	*
	*
	*/
    protected function _load_formfield_struct($xml = null)	
    {
		if(!isset($this->_xml)){
			return false;
		}
		$this->_formfield_struct = $this->update_block->struct_form->toArray();
		return true;			
	}	
	/*
	*	Load chuỗi xml mô tả đối tượng formfield
	*
	*
	*
	*/
    protected function _load_formfield_object($xml = null)	
    {
		if(!isset($this->_xml)){
			return false;
		}
		$this->_formfield_object = $this->update_block->formfield->toArray();
		return true;	
	}	
	/*
	*	Load chuỗi xml mô tả cấu trúc filter
	*
	*
	*
	*/
    protected function _load_filter_struct($xml = null)	
    {
		if(!isset($this->_xml)){
			return false;
		}
		$this->_filter_struct = $this->list_block->struct_filter->filter->toArray();
		return true;		
	}	
	/*
	*	Load chuỗi xml mô tả đối tượng filter
	*
	*
	*
	*/
    protected function _load_filter_object($xml = null)	
    {
		if(!isset($this->_xml)){
			return false;
		}
		$this->_filter_object = $this->list_block->filter_object->toArray();
		return true;			
	}	
	/*
	*	Load chuỗi xml mô tả danh sách đối tượng
	*
	*
	*
	*/
    protected function _load_list_object($xml = null)	
    {
		if(!isset($this->_xml)){
			return false;
		}
		$this->_list_object = $this->list_block->list_body->toArray();
		return true;		
	}
	/*
	*	Load thuộc tính form
	*
	*
	*
	*/
    protected function _load_updateform_option($xml = null)	
    {
		if(!isset($this->_xml)){
			return false;
		}
		$this->_updateform_option = $this->update_block->form_option->toArray();
		return true;		
	}	
	/*************************************************************************************************
	*-------------------------------------------------------------------------------------------------	
	*		OUTPUT
	*		Các hàm lấy dữ liệu đầu ra
	*/	
	/************************************************************************************************
	*
	*
	*/
	protected function _get_list_col()	
	{
		if(!isset($this->_xml)){
			return false;
		}
		if(!isset($this->_list_object)){
			$this->_load_list_object();
		}
		return $this->_list_object;
	}
}
